$(function () {

    $("#_dislog_close").click(function () {
        window.close();
    });


    $('.panel_tab .panel_tab_title li').click(function () {
        $('.panel_tab_con > div ').hide();
        $('.panel_tab_con > div').eq($(this).index()).show();
        $(this).addClass('current').siblings().removeClass('current');
    });


    createnews();



    $("body").click(function () {
        //字体颜色替换掉
        $(".div_item").each(function () {
            $(this).text($(this).text().replace("<span style='color:#d63737'>", "").replace("</span>", ""));
        });
        $("#div_items").css('display', 'none');
    });

    $("#message_input").keyup(function (e) {
        $("#_inputnumber").html(100 - $("#message_input").val().length);
        //字体颜色替换回来
        $(".div_item").each(function () {
            $(this).text($(this).text().replace("<span style='color:#d63737'>", "").replace("</span>", ""));
        });

        if ($("#message_input").val().length <= 0) {
            $(".div_item").css('display', 'none');//保持全部隐藏状态
            $("#div_items").css('display', 'none');//没有匹配就隐藏列表框
            return;
        }
        //如果输入，先将所有的选项隐藏
        $(".div_item").css('display', 'none');
        var itemNumber = 0;
        for (var i = 0; i < $(".div_item").length; i++) {
            //模糊匹配，将所有匹配项显示
            if ($(".div_item").eq(i).html().indexOf($("#message_input").val()) >= 0) {
                //匹配的字符串用 颜色标记
                $(".div_item").eq(i).html($(".div_item").eq(i).html().replace($("#message_input").val(), "<span style='color:#d63737'>" + $("#message_input").val() + "</span>"))
                $(".div_item").eq(i).css('display', 'block');
                itemNumber++;

            }
        }
        if (itemNumber > 0) {
            $("#div_items").css('display', 'block');//有匹配就显示列表框
        }
        itemNumber = 0;
    });

    $(".div_item").click(function () {
        $("#message_input").val($(this).text().replace("<span style='color:#d63737'>", "").replace("</span>", ""));//
        $("#_inputnumber").html(100 - $("#message_input").val().length);
    });


    document.onkeydown = function (event) {                //网页内按下回车触发
        var eve = event  || window.event;
        if (eve.keyCode == 13) {
            document.getElementById("_dialog_enter").click();
            return false;
        }
    }


    $("#_dislog_video").click(function () {
        $(".dialog_bottom_top").append('<div class="ask_div ask_left clearfix">'
            + '<div class="ask_div_head  ">'
            + ' <img src="images/robot_head.png"/>'
            + '</div>'
            + ' <div class="ask_div_con  ">'
            + '<p class="ask_p">2017-08-25<span class="ml10">12:00:35</span></p>' 
            + '<div class="ask_div_bg">'
            + '您是否想问下一问题？<a href="javascript:;" class="cole8">(点击即可获取答案)</a>'
            + ' <ul class="ask_div_ul">'
            + '<li>'
            + '<a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + '<li>'
            + '<a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + '<li>'
            + ' <a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + ' </ul>'
            + ' <p class="mt10">您还可以：</p>'
            + '<ul class="ask_div_ul">'
            + '<li>'
            + '<span>（1）点击专家视频<a href="http://www.faqrobot.org/price.htm" class="cole8">http://www.faqrobot.org/price.htm</a>转专家咨询</span>'
            + ' </li>'
            + '<li>'
            + ' <span>（2）点击在线客服<a href="http://www.fa.org/price.htm" class="cole8">http://www.fa.org/price.htm</a>转专家咨询</span>'
            + '</li>'
            + ' <li>'
            + '<span>（3）拨打<a href="javascript:;" class="cole8">010-12396</a>找专家寻求帮助</span>'
            + '</li>'
            + ' </ul>'
            + '</div>'
            + '</div>'
            + '</div>');
        $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
    });
    $("#_dialog_enter").click(function () {
        if ($("#message_input").val().length > 0) {
            var myDate = CurentTime().split(" ");
            //修改 20171117 开始
            $(".message_con").append('<div class="ask_div ask_right clearfix">'
                + '<div class="ask_div_head ">'
                + '<img src="images/persion.png"/>'
                + '</div>'
                + '<div class="ask_div_con  ans_con">'
                + '	<p>' + myDate[0] + '<span class="ml10">' + myDate[1] + '</span></p>'
                + '	<div class="ask_message">'
                + $("#message_input").val()
                + '	</div>'
                + '</div>'
                + '</div>');
            $("#message_input").val('');
            $("#_inputnumber").html(100);
            $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
        }
    });


    $("#_dislog_video").click(function () {
        $(".message_con").append('<div class="ask_div ask_left clearfix">'
            + '<div class="ask_div_head   ">'
            + ' <img src="images/robot_head.png"/>'
            + '</div>'
            + ' <div class="ask_div_con  ">'
            + '<p class="ask_p">2017-08-25<span class="ml10">12:00:35</span></p>' 
            + '<div class="ask_message">'
            + '您是否想问下一问题？<a href="javascript:;" class="cole8">(点击即可获取答案)</a>'
            + ' <ul class="ask_div_ul">'
            + '<li>'
            + '<a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + '<li>'
            + '<a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + '<li>'
            + ' <a href="javascript:;">1.这是一个问题</a>'
            + '</li>'
            + ' </ul>'
            + ' <p class="mt10">您还可以：</p>'
            + '<ul class="ask_div_ul">'
            + '<li>'
            + '<span>（1）点击专家视频<a href="javascript:;" class="cole8">http://www.faqrobot.org/price.htm</a>转专家咨询</span>'
            + ' </li>'
            + '<li>'
            + ' <span>（2）点击在线客服<a href="javascript:;" class="cole8">http://www.fa.org/price.htm</a>转专家咨询</span>'
            + '</li>'
            + ' <li>'
            + '<span>（3）拨打<a href="javascript:;" class="cole8">010-12396</a>找专家寻求帮助</span>'
            + '</li>'
            + ' </ul>'
            + '</div>'
            + '</div>'
            + '</div>');
        $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
    });
    $("#_dialog_enter").click(function () {
        if ($("#message_input").val().length > 0) {
            var myDate = CurentTime().split(" ");
            //修改 20171117 开始
            $(".message_con").append('<div class="ask_div ask_left clearfix">'
                + '<div class="ask_div_head">'
                + '<img src="images/persion.png"/>'
                + '</div>'
                + '<div class="ask_div_con  ans_con">'
                + '	<p>' + myDate[0] + '<span class="ml10">' + myDate[1] + '</span></p>'
                + '	<div class="ask_message">'
                + $("#message_input").val()
                + '	</div>'
                + '</div>'
                + '</div>');
            $("#message_input").val('');
            $("#_inputnumber").html(100);
            $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
        }
    });


       $("#Manualcustomerservice").click(function () {
        var myDate = CurentTime().split(" ");
        $(".message_con").append(' <div class="ask_div ask_left clearfix">'
            + '<div class="ask_div_head  ">'
            + '<img src="images/robot_head.png"/>'
            + '</div>'
            + ' <div class="ask_div_con fl">'
            + '<p class="ask_p">' + myDate[0] + '<span class="ml10">' + myDate[1] + '</span></p>'
            + '<div class="ask_message">'
            + ' 我们的收费有很多情况哦~如果您想知道我们的服务功能，点击这个链接<a href="javascript:;" class="cole8">http://www.faqrobot.org/price.htm</a>不过如果您的企业需要专业的只能机器人客服或者定制只能问答系统，那么您需要联系我们的客服人员进行咨询<a href="javascript:;" class="ask_qq"><img src="images/qq.png"/></a>'
            + '<div class="ask_btn">'
            + '<a href="javasript:;" style="margin-right:10px;">满意</a>'
            + '<a href="javasript:;">不满意</a>'
            + ' </div>'
            + '</div>'
            + '</div>'
            + '</div>');
        $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
    });


    
    $('.newslistmore').click(function(){
        $(this).prev().html( $(this).prev().html()+
    
          '	<li>'
+ '		<div class="tu"><img src="images/robot_head.png" /></div>'
+ '		<div class="nr">'
+ '			<h1>标题</h1>'
+ '			<p>aaaa <span>日期</span></p>'
+ '			<div class="th"><h6>地区</h6> <a class="nrmore">0</a></div>'
+ '		</div>'
+ '	</li>'
    
        );
    })


});


function createnews() {
    var myDate = CurentTime().split(" ");
    $(".message_con").append(' <div class="ask_div ask_left clearfix">'
        + '<div class="ask_div_head  ">'
        + '<img src="images/robot_head.png"/>'
        + '</div>'
        + ' <div class="ask_div_con fl">'
        + '<p class="ask_p">' + myDate[0] + '<span class="ml10">' + myDate[1] + '</span></p>'
        + '<div class="ask_message">'
       
        + '<ul class="newslist">'
+ '	<li>'
+ '		<div class="tu"><img src="images/robot_head.png" /></div>'
+ '		<div class="nr">'
+ '			<h1>标题</h1>'
+ '			<p>aaaa <span>日期</span></p>'
+ '			<div class="th"><h6>地区</h6> <a class="nrmore">0</a></div>'
+ '		</div>'
+ '	</li>'
 
+ '</ul>'
+ '<a class="newslistmore">加载更多</a>'



        + '</div>'
        + '</div>'
        + '</div>');
    $('.message_con').scrollTop($('.message_con')[0].scrollHeight);
}




function CurentTime() {
    var now = new Date();

    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日

    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var ss = now.getSeconds();          //秒
    var clock = year + "-";

    if (month < 10)
        clock += "0";

    clock += month + "-";

    if (day < 10)
        clock += "0";

    clock += day + " ";

    if (hh < 10)
        clock += "0";

    clock += hh + ":";
    if (mm < 10) clock += '0';
    clock += mm;

    clock += ":";
    if (ss < 10) clock += '0';
    clock += ss;
    return (clock);
}